home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Container / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  10.2 KB  |  371 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Part.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Container.hpp"
  11.  
  12. #ifndef PART_H
  13. #include "Part.h"
  14. #endif
  15.  
  16. #ifndef BINDING_K
  17. #include "Binding.k"
  18. #endif
  19.  
  20. #ifndef DEFINES_K
  21. #include "Defines.k"
  22. #endif
  23.  
  24. #ifndef CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. #ifndef FRAME_H
  29. #include "Frame.h"
  30. #endif
  31.  
  32. #ifndef SELECT_H
  33. #include "Select.h"
  34. #endif
  35.  
  36. #ifndef COMMANDS_H
  37. #include "Commands.h"
  38. #endif
  39.  
  40. #ifndef PROXY_H
  41. #include "Proxy.h"
  42. #endif
  43.  
  44. #ifndef VIEW_H
  45. #include "View.h"
  46. #endif
  47.  
  48. // ----- Part Layer -----
  49.  
  50. #ifndef FWABOUT_H
  51. #include "FWAbout.h"
  52. #endif
  53.  
  54. #ifndef FWPRESEN_H
  55. #include "FWPresen.h"
  56. #endif
  57.  
  58. #ifndef FWUTIL_H
  59. #include "FWUtil.h"
  60. #endif
  61.  
  62. #ifndef FWPRTITE_H
  63. #include "FWPrtIte.h"
  64. #endif
  65.  
  66. // ----- OS Layer -----
  67.  
  68. #ifndef FWCOLORP_H
  69. #include "FWColorP.h"
  70. #endif
  71.  
  72. #ifndef FWRECT_H
  73. #include "FWRect.h"
  74. #endif
  75.  
  76. #ifndef FWMENU_H
  77. #include "FWMenu.h"
  78. #endif
  79.  
  80. #ifndef FWCFMRES_H
  81. #include "FWCFMRes.h"
  82. #endif
  83.  
  84. #ifndef SLMIXOS_H
  85. #include "SLMixOS.h"
  86. #endif
  87.  
  88. #ifndef SLMIXOS_H
  89. #include "SLMixOS.h"
  90. #endif
  91.  
  92. #ifndef FWODGEOM_H
  93. #include "FWODGeom.h"
  94. #endif
  95.  
  96. // ----- ColorExtension Includes -----
  97.  
  98. #ifndef CESERVER_H
  99. #include "CEServer.h"
  100. #endif
  101.  
  102. // ----- OpenDoc Includes -----
  103.  
  104. #ifndef SOM_ODSession_xh
  105. #include <ODSessn.xh>
  106. #endif
  107.  
  108. #ifndef SOM_Module_OpenDoc_StdProps_defined
  109. #include <StdProps.xh>
  110. #endif
  111.  
  112. //========================================================================================
  113. // Runtime Information
  114. //========================================================================================
  115.  
  116. #ifdef FW_BUILD_MAC
  117. #pragma segment odfcontainer
  118. #endif
  119.  
  120. //========================================================================================
  121. //    Globals
  122. //========================================================================================
  123.  
  124. FW_DEFINE_CLASS_M1(CContainerPart, FW_CEmbeddingPart)
  125. FW_DEFINE_AUTO(CContainerPart)
  126.  
  127. //========================================================================================
  128. //    class CContainerPart
  129. //========================================================================================
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    CContainerPart::CContainerPart
  133. //----------------------------------------------------------------------------------------
  134.  
  135. CContainerPart::CContainerPart(ODPart* odPart) :
  136.     FW_CEmbeddingPart(odPart, FW_gInstance, kPartInfoID),
  137.     fPartContent(NULL),
  138.     fMainPresentation(NULL),
  139.     fBackgroundColor(56000, 56000, 65535)    // light blue
  140. {
  141.     FW_END_CONSTRUCTOR
  142. }
  143.  
  144. //----------------------------------------------------------------------------------------
  145. //    CContainerPart::~CContainerPart
  146. //----------------------------------------------------------------------------------------
  147.  
  148. CContainerPart::~CContainerPart()
  149. {
  150.     FW_START_DESTRUCTOR
  151. }
  152.  
  153. //----------------------------------------------------------------------------------------
  154. //    CContainerPart::Initialize
  155. //----------------------------------------------------------------------------------------
  156.  
  157. void CContainerPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)
  158. {
  159.     // ----- Call Inherited Initialize -----
  160.     FW_CEmbeddingPart::Initialize(ev, storageUnit, fromStorage);
  161.  
  162.     fDrawingSize.Set(FW_IntToFixed(kDrawingSizeX), FW_IntToFixed(kDrawingSizeY));
  163.  
  164.     // We instantiate a submenu item from the stream so we must
  165.     // prevent it from being deadstripped.
  166.     FW_DO_NOT_DEAD_STRIP(FW_CSubMenuItem);
  167.  
  168.     // ----- Tokenize -----
  169.     fContainerSelection = FW_NEW(CContainerSelection, (ev, this));    // Attention I don't own the selection the presentation will
  170.     
  171.     fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, kContainerView, kContainerView, fContainerSelection);
  172.     
  173.     CE_SetCallbacks(CContainerPart_SetColor, CContainerPart_SetColor);
  174.     CE_RegisterExtension(ev, this, this);
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. //    CContainerPart::NewPartContent
  179. //----------------------------------------------------------------------------------------
  180.  
  181. FW_CContent* CContainerPart::NewPartContent(Environment* ev)
  182. {
  183.     fPartContent = FW_NEW(CPartContent, (ev, this));
  184.     return fPartContent;
  185. }
  186.  
  187. //----------------------------------------------------------------------------------------
  188. //    CContainerPart::AddProxyToPart
  189. //----------------------------------------------------------------------------------------
  190.  
  191. void CContainerPart::AddProxyToPart(Environment* ev, CProxy* proxy)
  192. {
  193.     fPartContent->AddProxy(ev, proxy);
  194. }
  195.  
  196. //----------------------------------------------------------------------------------------
  197. //    CContainerPart::DetachProxy
  198. //----------------------------------------------------------------------------------------
  199. //    At the end the embedded frames associated with 'proxy' will be in limbo
  200.  
  201. void CContainerPart::DetachProxy(Environment* ev, CProxy* proxy)
  202. {
  203.     fPartContent->RemoveProxy(ev, proxy);
  204.     proxy->DetachEmbeddedFrames(ev);        // Set embedded frames to in limbo state
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208. //    CContainerPart::DeleteProxy
  209. //----------------------------------------------------------------------------------------
  210. //    At the end the embedded frames are completly gone
  211.  
  212. void CContainerPart::DeleteProxy(Environment* ev, CProxy* proxy)
  213. {
  214.     DetachProxy(ev, proxy);
  215.     delete proxy;
  216. }
  217.  
  218. //----------------------------------------------------------------------------------------
  219. // CContainerPart::AttachProxy
  220. //----------------------------------------------------------------------------------------
  221. //    Put back (for example after Undo) a proxy that has been detached
  222.  
  223. void CContainerPart::AttachProxy(Environment* ev, CProxy* proxy)
  224. {
  225.     AddProxyToPart(ev, proxy);    
  226.     proxy->AttachEmbeddedFrames(ev);
  227. }
  228.  
  229. //----------------------------------------------------------------------------------------
  230. //    CContainerPart::DoAbout
  231. //----------------------------------------------------------------------------------------
  232.  
  233. FW_Handled CContainerPart::DoAbout(Environment* ev)
  234. {
  235.     ::FW_About(ev, this, kAbout);
  236.     return FW_kHandled;
  237. }
  238.  
  239. //----------------------------------------------------------------------------------------
  240. //    CContainerPart::DoMenu
  241. //----------------------------------------------------------------------------------------
  242.  
  243. FW_Handled CContainerPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  244. {
  245.     FW_Handled result = FW_kHandled;
  246.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  247.  
  248.     switch (commandID)
  249.     {
  250.         case cSetBackgroundColor:
  251.             {
  252.                 FW_CColorPicker picker;
  253.                 
  254.                 picker.SetColor(GetBackgroundColor());
  255.                 if (picker.PickNewColor())
  256.                 {
  257.                     CSetBackgroundColorCommand* cmd = FW_NEW(CSetBackgroundColorCommand, (ev, this, picker.GetColor()));
  258.                     cmd->Execute(ev);
  259.                 }                
  260.             }
  261.             break;
  262.             
  263.         default:
  264.             result = FW_kNotHandled;        
  265.     }
  266.     
  267.     return result;
  268. }
  269.  
  270. //----------------------------------------------------------------------------------------
  271. //    CContainerPart::NewFrame
  272. //----------------------------------------------------------------------------------------
  273.  
  274. FW_CFrame* CContainerPart::NewFrame(Environment* ev, 
  275.                                 ODFrame* odFrame, 
  276.                                 FW_CPresentation* presentation,
  277.                                 FW_Boolean fromStorage)
  278. {
  279. FW_UNUSED(fromStorage);
  280.     return FW_NEW(CContainerFrame, (ev, odFrame, presentation, this));
  281. }
  282.  
  283. //----------------------------------------------------------------------------------------
  284. //    CDrawPart::DoAdjustMenus
  285. //----------------------------------------------------------------------------------------
  286.  
  287. FW_Handled CContainerPart::DoAdjustMenus(Environment* ev, 
  288.                                         FW_CMenuBar* menuBar, 
  289.                                         FW_Boolean hasMenuFocus, 
  290.                                         FW_Boolean isRoot)
  291. {
  292. FW_UNUSED(ev);
  293. FW_UNUSED(isRoot);
  294.     if (hasMenuFocus)
  295.         menuBar->EnableCommand(ev, kODCommandSelectAll, fPartContent->CountProxies() > 0);
  296.  
  297.     menuBar->EnableCommand(ev, cSetBackgroundColor, TRUE);
  298.  
  299.     return FW_kNotHandled;
  300. }
  301.  
  302. //----------------------------------------------------------------------------------------
  303. // CContainerPart::WhichProxy
  304. //----------------------------------------------------------------------------------------
  305.  
  306. CProxy* CContainerPart::WhichProxy(Environment* ev, FW_CGraphicContext& gc, 
  307.                 const FW_CPoint& where, FW_Boolean hasToBeSelected) const
  308. {
  309.     CContentProxyIterator ite(fPartContent);
  310.     for (CProxy* proxy = ite.Last(); ite.IsNotComplete(); proxy = ite.Previous())
  311.     {
  312.         FW_Boolean test = (!hasToBeSelected) || (hasToBeSelected && proxy->IsSelected());
  313.         if (test && proxy->HitTest(ev, gc, where))
  314.             return proxy;    
  315.     }
  316.     
  317.     return NULL;
  318. }
  319.  
  320. //----------------------------------------------------------------------------------------
  321. // CContainerPart::EmbeddedFrameRemoved
  322. //----------------------------------------------------------------------------------------
  323.  
  324. void CContainerPart::EmbeddedFrameRemoved(Environment *ev, FW_MProxy* proxy)
  325. {
  326.     CProxy* theProxy = (CProxy*)proxy;
  327.     
  328.     FW_CAcquiredODShape updateShape = ::FW_NewODShape(ev);
  329.     theProxy->GetUpdateBox(ev, updateShape);    
  330.     fMainPresentation->Invalidate(ev, updateShape);
  331.     
  332.     DeleteProxy(ev, theProxy);
  333. }
  334.  
  335. //----------------------------------------------------------------------------------------
  336. // CContainerPart::SetBackgroundColor
  337. //----------------------------------------------------------------------------------------
  338.  
  339. void CContainerPart::SetBackgroundColor(Environment* ev, const FW_CColor& newColor)
  340. {
  341.     if (IsReadOnly(ev))
  342.     {
  343.         FW_Beep();
  344.     }
  345.     else
  346.     {
  347.         if (newColor != fBackgroundColor)
  348.         {
  349.             fBackgroundColor = newColor;
  350.             FW_CPartFrameIterator iter(ev, this);
  351.             
  352.             for (CContainerFrame* frame = (CContainerFrame*)iter.First(ev); 
  353.                     iter.IsNotComplete(ev); frame = (CContainerFrame*)iter.Next(ev))
  354.             {
  355.                 frame->UpdateContainerProperties(ev);
  356.             }
  357.             fMainPresentation->Invalidate(ev);
  358.         }
  359.     }
  360. }
  361.  
  362. //----------------------------------------------------------------------------------------
  363. // CContainerPart_SetColor
  364. //----------------------------------------------------------------------------------------
  365.  
  366. void CContainerPart_SetColor(Environment* ev, void* refCon, short red, short green, short blue)
  367. {
  368.     FW_CColor newColor(red, green, blue);
  369.     ((CContainerPart*)refCon)->SetBackgroundColor(ev, newColor);
  370. }
  371.